import java.util.*;
import java.io.*;
public class AddressMain{
		
	static String menu_num;//이게 만약 번호 잘못 글자로 입력할 경우에 에러떠서 스트링으로 바꿨따.
	
	
	private static AddressBook AB = new AddressBook();

	static Scanner scan = new Scanner(System.in);
	String firstname, lastname, job, department, company, address, phone, fax, cellphone, email_addr, homepage;
	public static void main(String args[])
	{
		String password;
		AddressMain AM = new AddressMain();
		System.out.println("비밀 번호를 입력하세요");
		password=scan.next();
		if(password.equals("0000")){
			
			do{
				AM.call();
				menu_num=AM.menu();
				switch(menu_num){
				case "1":
					AM.add();
					break;
				case "2":
					AM.list();
					break;
				case "3":
					AM.show();
					break;
				case "4":
					AM.modify();
					break;
				case "5":
					AM.delete();
					break;
				case "6":
					AM.save();
					AM.end();
					break;
				case "0":
					System.out.println("잘못된 메뉴 번호 입니다. 다시 입력하세요!");
					AM.change();
					break;
				
				default:
					AM.menu();
					break;
					
				}
				}while(menu_num!="6");
		}
		else
			System.out.println("鍮꾨�踰덊샇媛���┰�덈떎. 醫낅즺�⑸땲��");
//		return 0;
	}
	
	
	public String menu(){
		
		
		System.out.println("1. 異붽�");//占쌨댐옙 占쏙옙占�
		System.out.println("2. 紐⑸줉");
		System.out.println("3. �곸꽭蹂닿린");
		System.out.println("4. �섏젙");
		System.out.println("5. ��젣");
		System.out.println("6. 醫낅즺");
		System.out.println("0. 鍮꾨�踰덊샇 蹂�꼍");
		System.out.println("============================");
		System.out.println("硫붾돱瑜��좏깮�섏꽭��: ");
		menu_num = scan.next();
		return menu_num;
	}
	
	public void add(){
		
		System.out.print("�대쫫���낅젰�섏꽭�� ");
		firstname=scan.next();
		System.out.print("�깆쓣 �낅젰�섏꽭��: ");
		lastname=scan.next();
		System.out.print("吏곸뾽���낅젰�섏꽭��: ");
		job=scan.next();
		System.out.print("遺�꽌瑜��낅젰�섏꽭��: ");
		department=scan.next();
		System.out.print("�뚯궗瑜��낅젰�섏꽭��: ");
		company=scan.next();
		System.out.print("二쇱냼瑜��낅젰�섏꽭��: ");
		address=scan.next();
		System.out.print("�꾪솕踰덊샇瑜��낅젰�섏꽭��: ");
		phone=scan.next();
		System.out.print("fax踰덊샇瑜��낅젰�섏꽭��: ");
		fax=scan.next();
		System.out.print("�대���踰덊샇瑜��낅젰�섏꽭��: ");
		cellphone=scan.next();
		System.out.print("�대찓��二쇱냼瑜��낅젰�섏꽭��: ");
		email_addr=scan.next();
		System.out.print("�덊럹�댁� 二쇱냼瑜��낅젰�섏꽭��: ");
		homepage=scan.next();
		AB.addAddr(firstname, lastname, job, department, company, address, phone, fax, cellphone, email_addr, homepage);	
	}
	
	public void list(){
		AB.showAddr();
	}
	
	public void show(){
		int choosenum;
		AB.showAddr();
		System.out.print("�먰븯���대쫫��踰덊샇 : ");
		choosenum=scan.nextInt();
		AB.showSpecific(choosenum);
	}
	
	public void modify(){
		System.out.print("�섏젙��紐⑸줉��踰덊샇瑜��낅젰�섏꽭��: ");
		int num;//�섏젙���щ엺��踰덊샇瑜�諛쏆쓬
		num= scan.nextInt();
		
		System.out.print("�대쫫(firstname)���낅젰�섏꽭��: ");
		firstname=scan.next();
		AB.modifyFirstname(num, firstname);
		
		System.out.print("��lastname)���낅젰�섏꽭��: ");
		lastname=scan.next();
		AB.modifyLastname(num, lastname);
		
		System.out.print("吏곸뾽���낅젰�섏꽭��: ");
		job=scan.next();
		AB.modifyJob(num, job);
		
		System.out.print("遺�꽌瑜��낅젰�섏꽭��: ");
		department=scan.next();
		AB.modifyDepartment(num, department);
		
		System.out.print("�뚯궗瑜��낅젰�섏꽭��: ");
		company=scan.next();
		AB.modifyCompany(num, company);
		
		System.out.print("二쇱냼瑜��낅젰�섏꽭��: ");
		address=scan.next();
		AB.modifyAddress(num, address);
		
		System.out.print("�꾪솕踰덊샇瑜��낅젰�섏꽭��: ");
		phone=scan.next();
		AB.modifyPhone(num, phone);
		
		System.out.print("�⑹뒪踰덊샇瑜��낅젰�섏꽭��: ");
		fax=scan.next();
		AB.modifyFax(num, fax);
		
		System.out.print("�몃뱶��踰덊샇瑜��낅젰�섏꽭��: ");
		cellphone=scan.next();
		AB.modifyCellhphone(num, cellphone);
		
		System.out.print("�대찓��二쇱냼瑜��낅젰�섏꽭��: ");
		email_addr=scan.next();
		AB.modifyEmailaddr(num, email_addr);
		
		System.out.print("�덊럹�댁� 二쇱냼瑜��낅젰�섏꽭��: ");
		homepage=scan.next();	
		AB.modifyHomepage(num, homepage);
		
	}
	
	public void delete(){
		int choosenum;
		AB.showAddr();
		System.out.print("��젣瑜��먰븯���대쫫��踰덊샇 : ");
		choosenum=scan.nextInt();
		AB.removeAddressbook(choosenum);
		
	}
	
	public void end(){
		
	}
	
	public void change(){
		
	}
	
	  public void save() {
	      try {
	          FileReader fr = new FileReader( "read.txt" ); //파일을 읽는 스트림 생성
	          FileWriter fw = new FileWriter( "write1.txt" ); //파일을 쓰는 스트림 생성

	          int input = 0;

	          while(( input = fr.read() ) != -1 ) { //2Byte씩 읽는다. 영문은 아스키 코드 한글은 유니코드로 읽는다. read()는 파일의 끝에서는 -1을 리턴한다.
	                System.out.print( (char)input ); //화면에 출력. 문자를 출력하기 위해서 int형 자료인 아스키 코드와 유니코드를 캐릭터 형으로 변환. 파일을 읽고 저장하는데 영향을 미치지 않는다.
	                fw.write( input ); // 다른 파일에 쓰는 부분
	          }
	          
	          fr.close(); // FileInputStream을 해제
	          fw.close(); // FileOutputStream을 해제
	         } catch ( IOException io ) {
	                System.out.println( io );
	      }
	     }//save() end
	  
	  
	  public void call() {
          
          try{
               BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
               String message = br.readLine();
               // FileReader fr = new FileReader(message);
               FileWriter fw = new FileWriter("c:/send.txt"); //저장안되면 c:/파일명 이런식으로 경로를 설정
              
               fw.write(message);
              
               fw.close();
         
          } catch(Exception e) {
              
          }

     }



}